﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Database;
using Business;
using System.Globalization;

namespace DT5_Anh09110006_Hung09110044_Vu09110157.QuanLy
{
    public partial class ThemLopHoc : System.Web.UI.Page
    {
        Business.QuanLyLopHoc qllophoc = new Business.QuanLyLopHoc();
        Business.QuanLyNhanVien qlnhanvien = new Business.QuanLyNhanVien();
        Business.QuanLyPhongHoc qlphonghoc = new Business.QuanLyPhongHoc();
        protected string ThoiGian = System.DateTime.Now.ToString("MM/dd/yyyy");
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                loaddulieu();
            }
        }
        private void loaddulieu()
        {
            ddlGiaoVien.DataSource = qlnhanvien.LayDanhSachGiangVien();
            ddlGiaoVien.DataTextField = "HoTenNV";
            ddlGiaoVien.DataValueField = "MaNV";
            ddlGiaoVien.DataBind();
            ddlPhongHoc.DataSource = qlphonghoc.LayDanhSachPhong();
            ddlPhongHoc.DataTextField = "TenPhong";
            ddlPhongHoc.DataValueField = "MaPhong";
            ddlPhongHoc.DataBind();

        }


        protected void btnQuayLai_Click(object sender, EventArgs e)
        {
            Response.Redirect("QuanLyLopHoc.aspx");
        }
        private void reset()
        {
              txtMaLop.Text="";              
               txtHocPhi.Text="";
               txtSiSo.Text="";
               txtLichHoc.Text="";
               txtMota.Text = "";
        }
        protected void btnThemLopHoc_Click(object sender, EventArgs e)
        {
            LopHoc lop = new LopHoc
            {
                MaLop=txtMaLop.Text,
                GiaoVienPT=ddlGiaoVien.SelectedValue,
                PhongHoc=ddlPhongHoc.SelectedValue,
                HocPhi=int.Parse(txtHocPhi.Text),
                SiSo = int.Parse(txtSiSo.Text),
                NgayKhaiGiang = System.DateTime.ParseExact(Request["NgayKhaiGiang"], "MM/dd/yyyy", CultureInfo.InvariantCulture),
                LichHoc=txtLichHoc.Text,
                MoTa=txtMota.Text
            };
            if (qllophoc.ThemLopHoc(lop))
            {
                Response.Write("<script language='javascript' type='text/javascript'>"
                              + " alert('Thêm lớp học thành công');"
                              + "</script>");
              
                reset();
               
            }
            else
            {
                Response.Write("<script language='javascript' type='text/javascript'>"
                             + " alert('Không thể thêm lớp học này');"
                             + "</script>");
            }
           
        }
    }
}